<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发起讨论 - 牛马</title>
    <link rel="icon" href="../image/logo.ico" type="image/x-icon">
    <script src="../js/head-nav.js"></script>
    <link rel="stylesheet" href="../plugs/layui/src/css/layui.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">

</head>

<body>
    <div class="main">
        <div class="container">
            <div class="row">
                <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1"></div>
                <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10">
                    <div class="publish-error-nav">
                        <h3>
                            <img th:src="@{/js/cursor.svg}" class="nav-title-icon">
                            &nbsp;讨论发表
                        </h3>
                    </div>
                    <hr>
                    <form id="ndiscuss" action="">
                        <div class="form-group">
                            <label for="title">标题</label>
                            <input type="text" class="form-control" id="title" name="title" placeholder="请输入标题"
                                autocomplete="off" data-rule="标题:required; length(0~30)">
                        </div>
                        <div class="form-group">
                            <label for="description">简介（简明扼要）</label>
                            <input type="text" class="form-control" id="description" name="description"
                                placeholder="请输入标题" autocomplete="off" data-rule="标题:required; length(0~30)">
                        </div>
                        <div id="input_discuss">
                            <label for="content">描述（请输入你需要发布的问题）</label>
                            <textarea required placeholder="请输入" class="layui-textarea" id="discuss_info"
                                name="content"></textarea>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary"
                                onclick="javascript:history.go(-1);return false;">取消</button>
                            <button type="button" class="btn btn-primary" onclick="onSubmit()">发布</button>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1"></div>
                    </form>
                </div>
            </div>

            <script src="../js/bootstrap.min.js"></script>
            <script src="../js/jquery.min.js"></script>
            <script>
                $(function () {
                    token = localStorage.getItem("token");
                    if (token == null) {
                        alert("请先登录")
                        window.location.href = 'login.html'
                    }
                })
                onSubmit = function () {
                    var fields = $('#ndiscuss').serializeArray();
                    var obj = {};
                    $.each(fields, function (index, field) {
                        obj[field.name] = field.value;
                    })
                    console.log(obj);
                    $.ajax({
                        type: "post",
                        headers: { token: localStorage.getItem("token") },
                        url: "http://localhost:70/devu/discuss/newdiscuss",
                        contentType: 'application/json',
                        dataType: 'JSON',
                        data: JSON.stringify(obj),
                        success: function (res) {
                            layer.msg('评论成功...', { icon: 1, anim: 6 ,time:2},function(){
                                window.location.href="index.html"
                            });
                        },
                    })
                }

            </script>
            <script src="../js/bottom-nav.js"></script>
</body>

</html>